<style lang='scss' scoped>
	.alldingdan {
		font-size: 24rpx;
		padding: 20rpx;
		background-color: #ccc;

		.list {
			padding: 20rpx;
			box-sizing: border-box;
			margin: 10rpx;
			background-color: #fff;

			.title {
				display: flex;
				justify-content: space-between;
			}

			.orders {
				display: flex;

				image {
					width: 300rpx;
					box-sizing: border-box;
					height: 200rpx;
					padding: 20rpx;
					vertical-align: middle;
				}

				.warp {
					flex: 1;
					padding: 30rpx 0;
					display: flex;
					flex-flow: column;
					justify-content: space-between;

					view {
						display: -webkit-box;
						-webkit-line-clamp: 2;
						overflow: hidden;
						text-overflow: ellipsis;
						-webkit-box-orient: vertical;
					}
				}
			}

			.footer {
				display: flex;
				justify-content: space-between;
			}
		}
	}
</style>
<template>
	<view class='alldingdan'>
		<view class="list" v-for="(item,index) in orderslist" :key="index">
			<div class="title">
				<text>订单号:{{item.order_number}}</text>
				<text>创建时间:{{ filterTime(item.create_time)}}</text>
			</div>
			<view class="orders" v-for="(v,i) in item.goods" :key="index">
				<image :src="v.goods_small_logo || '../../static/52b1464290643af26775f95b539de4c0.jpeg'">
				</image>
				<view class="warp">
					<view> {{v.goods_name}}</view>
					<text>¥{{v.goods_price}}X{{v.goods_number}}</text>
				</view>
			</view>
			<view class="footer">
				<text></text>
				<view class="jiage">
					一共付款 {{item.total_price}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		api
	} from "@/utils/index.js"
	export default {
		data() {
			return {
				orderslist: []
			}
		},
		onLoad(o) {},
		onShow() {
			api({
				url: 'public/v1/my/orders/all?type=1'
			}).then(res => {
				console.log(res.message);
				this.orderslist = res.message.orders
			})
		},
		methods: {
			filterTime(val) {
				let result;
				let timePublish = new Date(val * 1); // 传入的时间
				let timeNow = new Date(); // 现在的时间
				let minute = 1000 * 60;
				let hour = minute * 60;
				let day = hour * 24;
				let month = day * 30;
				let year = month * 12;
				let diffValue = timeNow - timePublish; // 时间相差的值，是毫秒
				//   console.log(diffValue);
				let diffMonth = diffValue / month;
				let diffWeek = diffValue / (7 * day);
				let diffDay = diffValue / day;
				let diffHour = diffValue / hour;
				let diffMinute = diffValue / minute;
				let diffYear = diffValue / year;
				if (diffValue < minute) {
					result = '刚刚';
				} else if (diffYear > 1) {
					result = parseInt(diffYear) + '年前';
				} else if (diffMonth > 1) {
					result = parseInt(diffMonth) + '月前';
				} else if (diffWeek > 1) {
					result = parseInt(diffWeek) + '周前';
				} else if (diffDay > 1) {
					result = parseInt(diffDay) + '天前';
				} else if (diffHour > 1) {
					result = parseInt(diffHour) + '小时前';
				} else if (diffMinute > 1) {
					result = parseInt(diffMinute) + '分钟前';
				}
				return result;
			}
		}
	}
</script>
